package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.SpecimenImage;
import com.fsnbigdata.domain.QSpecimenImage;
import com.fsnbigdata.domain.Specimen;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = SpecimenImageRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = SpecimenImageRepositoryCustom.class)
@Transactional(readOnly = true)
public class SpecimenImageRepositoryImpl extends QueryDslRepositorySupportExt<SpecimenImage> implements SpecimenImageRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    SpecimenImageRepositoryImpl() {
        super(SpecimenImage.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LOCATION = "location";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CODE = "code";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CREATE_DATE = "createDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DESCRIPTION = "description";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String AUTHOR = "author";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SPECIMEN = "specimen";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String URL = "url";

    /**
     * TODO Auto-generated method documentation
     *
     * @param specimen
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<SpecimenImage> findBySpecimen(Specimen specimen, GlobalSearch globalSearch, Pageable pageable) {
        QSpecimenImage specimenImage = QSpecimenImage.specimenImage;
        JPQLQuery<SpecimenImage> query = from(specimenImage);
        Assert.notNull(specimen, "specimen is required");
        query.where(specimenImage.specimen.eq(specimen));
        Path<?>[] paths = new Path<?>[] { specimenImage.specimen, specimenImage.code, specimenImage.description, specimenImage.location, specimenImage.author, specimenImage.url, specimenImage.createDate };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(SPECIMEN, specimenImage.specimen).map(CODE, specimenImage.code).map(DESCRIPTION, specimenImage.description).map(LOCATION, specimenImage.location).map(AUTHOR, specimenImage.author).map(URL, specimenImage.url).map(CREATE_DATE, specimenImage.createDate);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, specimenImage);
    }
}
